package com.zhangfb95.crosschain.infra.controller.starter.httplog;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;
import java.util.Map;

/**
 * @author zhangfubing
 * @since 2019/5/25
 */
@Getter
@Setter
@ConfigurationProperties("biz.starter.httplog")
public class StarterProperties {

    /**
     * 是否开启记录http日志
     */
    private boolean enabled = true;

    /**
     * 忽略的url列表
     */
    private List<String> ignoreUrl;

    /**
     * mdc日志和http请求头的映射
     */
    private Map<String, String> mdcHttpHeaderMap;

    /**
     * 日志记录级别，仅支持传入info、debug
     */
    private String level;

    public boolean canLog(String url) {
        if (!enabled) {
            return false;
        }

        if (ignoreUrl == null) {
            return true;
        }
        return !ignoreUrl.contains(url);
    }
}
